# $Id: PKGBUILD 160421 2012-06-01 20:13:34Z stephane $
# Maintainer: Stéphane Gaudreault <stephane@archlinux.org>
# Contributor: Sergej Pupykin <pupykin.s@arch@gmail.com>
# Contributor: Andreas Wagner <Andreas.Wagner@em.uni-frankfurt.de>

pkgname=heirloom-mailx
pkgver=12.5
pkgrel=3
pkgdesc="A commandline utility for sending and receiving email"
arch=('i686' 'x86_64')
url="http://heirloom.sourceforge.net/mailx.html"
license=('custom')
groups=('base')
depends=('openssl' 'krb5')
optdepends=('smtp-forwarder: for sending mail')
replaces=('mailx' 'mailx-heirloom')
provides=('mailx' 'mailx-heirloom')
conflicts=('mailx' 'mailx-heirloom')
backup=(etc/mail.rc)
source=(ftp://ftp.archlinux.org/other/${pkgname}/${pkgname}-${pkgver}.tar.xz)
sha1sums=('1998dd6168a68400e533712ae7163c72b6a7c056')
options=('!makeflags') # Does not build with MAKEFLAGS=-jX, X>1

# source PKGBUILD && mksource
mksource() {
  export CVSROOT=:pserver:anonymous@nail.cvs.sourceforge.net:/cvsroot/nail
  D=nail
  [ -d "${D}" ] && cvs up "${D}" || cvs co "${D}"
  
  _dirname=${pkgname}-${pkgver}
  mv $D ${_dirname}
  tar -cJv --exclude=CVS -f ${_dirname}.tar.xz ${_dirname}
  rm -rf ${_dirname}
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  sed -i 's|/etc/nail.rc|/etc/mail.rc|g' mailx.1

  # For Linux and BSD, this should be set.
  echo "set bsdcompat" >> nail.rc

  sed -i "s/pg/less/" cmd1.c

  echo PREFIX=/usr \
       MAILRC=/etc/mail.rc \
       SENDMAIL=/usr/sbin/sendmail \
       MAILSPOOL=/var/spool/mail \
       UCBINSTALL=/usr/bin/install > makeflags

  make `cat makeflags` IPv6=-DHAVE_IPv6_FUNCS
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make DESTDIR="${pkgdir}" `cat makeflags` install

  # For compatibility with the old mailx program
  ln -sf mailx "${pkgdir}"/usr/bin/mail
  ln -sf mailx.1.gz "${pkgdir}"/usr/share/man/man1/mail.1.gz

  install -D -m0644 COPYING "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE
}
